﻿using FB.Data.Models;
using FB.Enums;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;

namespace FB.Providers.EmployeeInfo
{
    [Table("emp_Employees")]
    public class Employee : FBAuditModel, IRecordState, IEmployeeInfoEntity, IPersonalInfo, IFullName
    {
        public Employee() { }

        [Key, StringLength(16)]
        [Display(ResourceType = typeof(Resources.Models.EmployeeInfo), Name = "EMPCode")]
        public string EMPCode { get; set; }

        [StringLength(16)]
        [Display(ResourceType = typeof(Resources.Models.EmployeeInfo), Name = "RefCode")]
        public string RefCode { get; set; }

        [StringLength(256)]
        [Display(ResourceType = typeof(Resources.Models.EmployeeInfo), Name = "LastName")]
        public string LastName { get; set; }

        [StringLength(256)]
        [Display(ResourceType = typeof(Resources.Models.EmployeeInfo), Name = "FirstName")]
        public string FirstName { get; set; }

        [StringLength(256)]
        [Display(ResourceType = typeof(Resources.Models.EmployeeInfo), Name = "Alias")]
        public string Alias { get; set; }

        [StringLength(256), Column("CHNName")]
        [Display(ResourceType = typeof(Resources.Models.EmployeeInfo), Name = "ChineseName")]
        public string ChineseName { get; set; }

        [StringLength(1)]
        [Display(ResourceType = typeof(Resources.Models.EmployeeInfo), Name = "Gender")]
        public string Gender { get; set; }

        [Required, StringLength(2)]
        [Display(ResourceType = typeof(Resources.Models.EmployeeInfo), Name = "EMPType")]
        public string EMPType { get; set; }

        [Required, EnumDataType(typeof(Enums.EmployeeStatus))]
        [Display(ResourceType = typeof(Resources.Models.EmployeeInfo), Name = "Status")]
        public Enums.EmployeeStatus Status { get; set; }

        [StringLength(256)]
        [Display(ResourceType = typeof(Resources.Models.EmployeeInfo), Name = "Email")]
        public string Email { get; set; }

        [StringLength(32)]
        [Display(ResourceType = typeof(Resources.Models.EmployeeInfo), Name = "Mobile")]
        public string Mobile { get; set; }

        [StringLength(32)]
        [Display(ResourceType = typeof(Resources.Models.EmployeeInfo), Name = "ExtensionNo")]
        public string ExtensionNo { get; set; }

        [DataType(DataType.Date)]
        [Display(ResourceType = typeof(Resources.Models.EmployeeInfo), Name = "TerminationDate")]
        public DateTime? TerminationDate { get; set; }

        [StringLength(8)]
        [Display(ResourceType = typeof(Resources.Models.EmployeeInfo), Name = "TerminationType")]
        public string TerminationType { get; set; }

        [StringLength(256)]
        [Display(ResourceType = typeof(Resources.Models.EmployeeInfo), Name = "UserName")]
        public string UserName { get; set; }

        [Display(ResourceType = typeof(Resources.Models.EmployeeInfo), Name = "UserID")]
        public Guid? UserID { get; set; }


        [Display(ResourceType = typeof(Resources.Models.EmployeeInfo), Name = "RecordState")]
        [Column("RecordState"), EnumDataType(typeof(RecordState))]
        public RecordState RecordState { get; set; }



        [ForeignKey("EMPType")]
        public virtual EmployeeType EmployeeType { get; set; }

        
        public virtual ICollection<Employee> Subordinates { get; set; }
        public virtual ICollection<Employee> Supervisors { get; set; }

        
        [ForeignKey("EMPCode")]
        public virtual ICollection<EmployeeInPosition> PostDetails { get; set; }


        public int? LocationID { get; set; }


        [NotMapped]
        public string FullName
        {
            get
            {
                var f = new StringBuilder();
                if (!string.IsNullOrEmpty(LastName)) f.AppendFormat("{0} ", LastName);
                if (!string.IsNullOrEmpty(FirstName)) f.AppendFormat("{0} ", FirstName);
                if (!string.IsNullOrEmpty(Alias)) f.AppendFormat("{0} ", Alias);
                if (!string.IsNullOrEmpty(ChineseName)) f.AppendFormat("{0} ", ChineseName);

                return f.ToString();
            }
        }
    }
  

}
